#include<signal.h>
#include<iostream>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>

using namespace std;
void catchsig(int signum)
{
    cout<<"进程捕捉到的信号为："<<signum<<"  ,pid:"<<getpid()<<endl;
}
int main()
{
    //signal(SIGINT,fun);
    // signal(2,catchsig);

    // while(true)
    // {
    //     cout<<"当前进程正在运行..."<<"pid:"<<getpid()<<endl;
    //     sleep(1);
    // }

    if(fork()==0)
    {
        cout<<"子进程："<<getpid()<<"正在执行"<<endl;
        sleep(5);
        int a = 1/0;
        exit(1);
    }
    int status = 0;
    waitpid(-1,&status,0);
    cout<<"退出码："<<((status>>8)&0xff)<<"  core_dump:"<<((status>>7)&1)<<"  信号"<<(status&0x7f)<< endl;
    return 0;
}
